package com.xianbeiying.app.ckgl.model;

import android.content.Context;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.xianbeiying.app.ckgl.MyApplication;
import com.xianbeiying.app.ckgl.bean.JsonBean;
import com.xianbeiying.app.ckgl.bean.UrlBean;
import com.xianbeiying.app.ckgl.http.HttpPostManger;
import com.xianbeiying.app.ckgl.util.DialogUtile;
import com.xianbeiying.app.ckgl.util.LogUtils;

import cz.msebera.android.httpclient.Header;

/**
 * 更新版本
 */
public class UpdateModel extends BaseModel {

    private AsyncHttpClient client;
    private RequestParams params;
    private Context context;

    public UpdateModel(Context context) {
        this.context = context;
        client = new AsyncHttpClient();
        params = new RequestParams();
    }

   /**
    * apk更新
    * */
    public void UpdateApk(String k, boolean isDiaylog) {
        if (isDiaylog) {
            DialogUtile.showLoading(context);
        }
        String url= JsonBean.oneString(k);
        LogUtils.e("url","http://"+ MyApplication.IP+UrlBean.UPGRADE_VERSION+url+"======");
        HttpPostManger.post(context,"http://"+ MyApplication.IP+UrlBean.UPGRADE_VERSION, url, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                //关闭加载
                DialogUtile.closeDialog();
                LogUtils.e("返回值", new String(responseBody) + "----------------");
                //函数返回值
                UpdateModel.this.onCallBackData("更新apk", responseBody);
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                //关闭加载
                DialogUtile.closeDialog();
                LogUtils.e("返回值", statusCode + "----------------");
            }
        });
    }
}
